from PIL import Image, ImageDraw, ImageFont
import random
from io import BytesIO
import string


def random_color():
    return random.randint(0,245),random.randint(0,245),random.randint(0,245)


def generate_code():
    width = 60*4
    height = 60
    image = Image.new('RGB',(width,height),(200,200,200))
    font = ImageFont.truetype('Arial.ttf', 36)
    draw = ImageDraw.Draw(image)

    random_formula = random.choice(string.digits) + "+" + random.choice(string.digits) + "="
    draw.text((60 * 1 + 5, 10), random_formula, font=font, fill=random_color())



    out = BytesIO()
    image.save(out, format='JPEG')
    return random_formula,out.getvalue()

if __name__ == '__main__':
    print(generate_code())